Skip to main content

Maven Project Structure

One of the biggest advantages of Maven is that it enforces a standard project structure.
For automation testing engineers, this structure brings clarity, consistency, and scalability.

Understanding this structure is mandatory before working with pom.xml, TestNG, or CI/CD pipelines.


Why Project Structure Matters in Automation

In automation projects:

  • Tests grow rapidly
  • Multiple engineers contribute
  • CI tools execute tests automatically

A standard structure ensures:

  • Everyone knows where code belongs
  • Tools work without extra configuration
  • Maintenance becomes easier

Maven solves this by defining convention over configuration.


Standard Maven Project Layout

project-root/

├─ pom.xml

├─ src/
│ ├─ main/
│ │ ├─ java/
│ │ └─ resources/
│ │
│ └─ test/
│ ├─ java/
│ └─ resources/

└─ target/

Each folder has a specific purpose.


pom.xml (Project Object Model)

pom.xml
  • Heart of the Maven project
  • Defines dependencies, plugins, build rules
  • Controls how tests are executed

👉 This will be covered in detail in the pom.xml – MASTER CONTROL FILE section.


src/main/java

src/main/java

Purpose

  • Application source code (rare in pure automation projects)

In Automation Projects

Usually contains:

  • Utility classes
  • Framework core code
  • API clients
  • Custom libraries

Example:

src/main/java
└─ framework/
├─ driver/
├─ utils/
└─ config/

src/main/resources

src/main/resources

Purpose

  • Non-Java resources required by main code

Examples:

  • log4j.properties
  • application.properties
  • JSON / XML templates
  • Environment configs

These files are automatically added to the classpath.


src/test/java ⭐ (Most Important for Automation)

src/test/java

Purpose

  • All test-related Java code

This is where you place:

  • TestNG test classes
  • Test classes using Selenium / RestAssured
  • Step definitions
  • Test runners

Example structure:

src/test/java
└─ tests/
├─ login/
├─ payment/
└─ regression/

Maven automatically treats this folder as test code.


src/test/resources

src/test/resources

Purpose

  • Test-specific non-Java files

Common contents:

  • testng.xml
  • Test data files (CSV, JSON, Excel)
  • Environment config files
  • Feature files (BDD)

Example:

src/test/resources
├─ testng/
│ ├─ smoke.xml
│ └─ regression.xml
├─ testdata/
└─ config/

target/ Directory

target/

Purpose

  • Generated by Maven during build
  • Contains compiled code, reports, logs

Common contents:

  • surefire-reports
  • TestNG reports
  • Compiled .class files

⚠️ This folder should never be committed to Git.


How Maven Uses This Structure

When you run:

mvn test

Maven automatically:

  1. Compiles code in src/main/java
  2. Compiles code in src/test/java
  3. Loads resources from src/*/resources
  4. Executes tests
  5. Generates reports in target/

No extra configuration required.


Automation Engineer Best Practices

  • Keep framework code in src/main/java
  • Keep tests only in src/test/java
  • Store testng.xml in src/test/resources
  • Organize tests by feature or module
  • Never hardcode environment values in code

Common Mistakes

  • Placing tests in src/main/java
  • Mixing framework and test logic
  • Committing target/ directory
  • Storing credentials in source code
  • Ignoring resource folders

Key Takeaways

  • Maven project structure is fixed and intentional
  • Automation tools rely on this structure
  • Correct structure reduces configuration effort
  • CI/CD works smoothly with standard layout
  • Mastering this structure is essential before pom.xml